﻿using System.Collections.Generic;
using System.Linq;
using SacNetUG.Models;

namespace SacNetUG.Tests.Fakes
{
    public class FakeDataContextWrapper : IDataContextWrapper
    {
        private readonly FakeDatabase _fakeDatabase;

        public FakeDataContextWrapper(FakeDatabase database)
        {
            _fakeDatabase = database;
        }

        #region IDataContextWrapper Members

        public IQueryable<T> Table<T>() where T : class
        {
            var result = (List<T>)_fakeDatabase.Tables[typeof(T)];
            return result.AsQueryable();
        }

        public void DeleteAllOnSubmit<T>(IEnumerable<T> entities) where T : class
        {
            foreach (var entity in entities)
            {
                Table<T>().ToList().Remove(entity);
            }
        }

        public void DeleteOnSubmit<T>(T entity) where T : class
        {
            Table<T>().ToList().Remove(entity);
        }

        public void InsertOnSubmit<T>(T entity) where T : class
        {
            Table<T>().ToList().Add(entity);
        }

        public void SubmitChanges()
        {
        }

        public void Dispose()
        {
        }

        public List<MissingKid> GetMissingKids()
        {
            return new List<MissingKid>{new MissingKid()};
        }

        #endregion
    }
}